home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir42 / c7105.zip / FORM.TPX < prev    next >
Text File  |  1994-03-02  |  21KB  |  469 lines

  1. #!┌───────────────────────────┤Template Segment├───────────┬─────────────────┐
  2. #!│                                Form.TPX                │Version: 3007.105│
  3. #!├───────────────────────────────┤Contents├───────────────┴─────────────────┤
  4. #!│Structure             Type       Description                              │
  5. #!│────────────────────  ─────────  ─────────────────────────────────────────│
  6. #!│                      PROCEDURE  Update a browse or lookup with a form    │
  7. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  8. #!│Version   Comments                                                        │
  9. #!│────────  ────────────────────────────────────────────────────────────────│
  10. #!│3007.000  Release of CDD3 version 3007 templates                          │
  11. #!│3007.100  Repaired Form Procedure                                         │
  12. #!│3007.101  Modified Form Procedure                                         │
  13. #!│3007.103  Modified Form Procedure                                         │
  14. #!│3007.105  Modified Form Procedure                                         │
  15. #!└──────────────────────────────────────────────────────────────────────────┘
  16. #!
  17. #PROCEDURE(Form,'Update a browse or lookup with a form'),SCREEN,PULLDOWN
  18. #!
  19. #!┌──────────────────────────┤Procedure Template├──────────┬─────────────────┐
  20. #!│                                  Form                  │Version: 3007.103│
  21. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  22. #!│The Form Template generates a file update procedure.  A procedure         │
  23. #!│generated with this template assumes that:                                │
  24. #!│ 1.  Keycode will be Enter, Insert or Delete upon procedure initialization│
  25. #!│ 2.  If Keycode is Enter or Delete, the record buffer contains a valid    │
  26. #!│     record, and that record reflects the current active record of Primary│
  27. #!│ 3.  If Keycode is Insert, the record buffer contains a cleared record,   │
  28. #!│     with any necessary key fields primed.                                │
  29. #!│Upon completion of Editing or deleting a record, the Form procedure will  │
  30. #!│process any files referenced to Primary in a 1:Many constrained           │
  31. #!│relationship.                                                             │
  32. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  33. #!│Version   Comments                                                        │
  34. #!│────────  ────────────────────────────────────────────────────────────────│
  35. #!│3007.000  Release of CDD3 version 3007 templates                          │
  36. #!│3007.100  Repaired CANCEL code (on single entry forms, called as deletes, │
  37. #!│          the CANCEL field code should not perform a GET(file,0).  This   │
  38. #!│          repair fixes a problem with cancelled deletes affecting totals  │
  39. #!│          on the calling browse procedure.                                │
  40. #!│3007.101  Added "Disable RI Logout" Prompt.  This prompt is added to allow│
  41. #!│          the disabling of the LOGOUT function during RI Updates and      │
  42. #!│          Deletes.  This is necessary if RI Code is generated to handle   │
  43. #!│          multiple relations between files.                               │
  44. #!│3007.103  Added Enabling of LOC:Message on Delete Action (mainly for GUI) │
  45. #!│3007.105  Completed support for PullDowns                                 │
  46. #!│          Moved call to ShowWarning in I/O code to WARNINGS.TPX           │
  47. #!│          Repaired Change Action code with regard to AutoNumber ADDs      │
  48. #!└──────────────────────────────────────────────────────────────────────────┘
  49. #!
  50. #PROTOTYPE('')
  51. #PROMPT('Insert message',@S30),%InsertMsg
  52. #PROMPT('Chan&ge message',@S30),%ChangeMsg
  53. #PROMPT('De&lete message',@S30),%DeleteMsg
  54. #PROMPT('Action after ADD',OPTION),%AddAction
  55. #PROMPT('Return to caller ',RADIO)
  56. #PROMPT('Retain Record    ',RADIO)
  57. #PROMPT('Clear Record     ',RADIO)
  58. #PROMPT('Copy field hot&key:',KEYCODE),%CopyKey
  59. #PROMPT('Next &Procedure ',PROCEDURE),%NextProcedure
  60. #PROMPT('Disable RI Logout',CHECK),%NoLogoutSupport
  61. #INSERT(%StandardHeader)
  62. #INSERT(%InitFormSymbols)
  63. #INSERT(%PrimaryDriverCheck)
  64. #IF(%Primary = %NULL)
  65.   #SET(%ErrorMessage,(' WARNING during Code Generation in Procedure: '& %Procedure ))
  66.   #ERROR(%ErrorMessage)
  67.   #SET(%ErrorMessage,( ' No File Defined In File Schematic For FORM Template '))
  68.   #ERROR(%ErrorMessage)
  69. #ENDIF
  70. %Procedure      PROCEDURE
  71.  
  72. %LocalData
  73.  
  74. NoMoreFields       BYTE(0)                       !No more fields flag
  75. NonStopSelect      BYTE(0)
  76. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  77.   #IF(%CopyKey)
  78. SCREEN    %ScreenAttributes,ALRT(%CopyKey)
  79. %ScreenPaintDeclarations
  80. %ScreenStringDeclarations
  81. %ScreenFieldDeclarations
  82.           .
  83.     #IF(%SharedFiles = %NULL)
  84.       #IF(%PrimaryDriver <> 'Btrieve')
  85. SAV:SaveRecord     LIKE(%FilePre:Record),PRE(SAV)
  86.       #ENDIF
  87.     #ENDIF
  88.   #ELSE
  89. %ScreenStructure
  90.     #IF(%SharedFiles = %NULL)
  91.       #IF(%PrimaryDriver <> 'Btrieve')
  92. SAV:SaveRecord     LIKE(%FilePre:Record),PRE(SAV)
  93.       #ENDIF
  94.     #ENDIF
  95.   #ENDIF
  96. #ELSE
  97. %ScreenStructure
  98. #ENDIF
  99. #IF(%PullDown)
  100. %PullDownStructure
  101. SAV::PullDownOpened BYTE(0)
  102. #ENDIF
  103. #IF(%SharedFiles OR %PrimaryDriver = 'Btrieve')
  104. RecordQueue        QUEUE,PRE(SAV)                !Queue for concurrency checking
  105. SaveRecord           LIKE(%FilePre:Record),PRE(SAV) #<!size of primary file record
  106. #FOR(%FileMemo)
  107. #FIX(%Field,%FileMemo)
  108. SAV:%FieldID         STRING(SIZE(%FileMemo))
  109. #ENDFOR
  110.                    END                           #<!End Queue structure
  111. #ENDIF
  112. #INSERT(%FileControl)                            #!Declare Flags for file access
  113. AbortTransaction   BYTE
  114. #IF(%RelatedChildList)
  115.   #SET(%ProcessingFile,%Primary)
  116. #INSERT(%RelationalAccessFlds)                   #<!Declare link fields
  117. RI:RestrictUpdate  BYTE
  118. RI:RestrictDelete  BYTE
  119.   #IF(%PrimaryDriver = 'Paradox3')
  120.     #FIX(%File,%Primary)
  121. UpdRelation        STRING(SIZE(%FilePre:Record)) #<!Position of last related record
  122.   #ELSE
  123. UpdRelation        STRING(10)                    #<!Position of last related record
  124.   #ENDIF
  125.   #IF(%PrimaryDriver='Btrieve')
  126. SAV:Position       STRING(255)
  127.   #ENDIF
  128. #ENDIF
  129. #INSERT(%DeclareAutoInc)
  130. #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  131. LastPosition  STRING(10)                         !Position of last ADD
  132. #ENDIF
  133. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  134.   #IF(%CopyKey)
  135. #INSERT(%FieldDups)
  136.   #ENDIF
  137. #ENDIF
  138. #IF(%PrimeKeysExist)
  139. #INSERT(%SavePrimedFields)
  140. #ENDIF
  141. #EMBED('Data Section')
  142.  
  143.   CODE
  144.  
  145.   #EMBED('Setup Procedure')
  146.   #INSERT(%FileControl)                          #!Open files
  147.   #INSERT(%SavePrimaryLinks)
  148.   NonStopSelect = FALSE
  149.   CASE KEYCODE()                                 !What Key was pressed?
  150.   OF InsKey                                      !Insert a new record
  151.     Action = AddRecord                           !Set action code 1 (ADD)
  152.     #INSERT(%InsertMessage)                      #<!Message for ADD RECORD
  153.   #IF(%AutoInc)
  154.     DO AutoNumber                                !Set autonumber key field(s)
  155.   #ELSE
  156.     #INSERT(%ClearValues)
  157.   #ENDIF
  158.     #EMBED('On Add After Record Buffer Is Cleared')
  159.   #IF(%InitRoutine)                              #<!Field(s) initial value
  160.     DO InitializeFields                          !Initial values from dictionary
  161.   #ENDIF
  162.   OF EnterKey                                    !Process a CHANGE request
  163.   OROF MouseLeft2                                !on EnterKey or double mouse
  164.     Action = ChangeRecord                        !Set action code 2 (CHANGE)
  165.     #INSERT(%ChangeMessage)                      #<!Message for CHANGE RECORD
  166.   #IF(%SharedFiles)
  167.     #INSERT(%SetupConcurrency)                   #<!Setup multi-user Concurrency
  168.   #ENDIF
  169.   OF DelKey                                      !Process a DELETE request
  170.     Action = DeleteRecord                        !Set action code 3 (DELETE)
  171.     #INSERT(%DeleteMessage)                      #<!Message for DELETE RECORD
  172.     SavePointer = POSITION(%Primary)             #<!Position in PRIMARY file
  173.   END                                            !End CASE Keycode
  174.   #FOR(%Formula)
  175.     #IF(UPPER(%FormulaClass) = 'SETUP')
  176.   #INSERT(%GenerateFormula)
  177.     #ENDIF
  178.   #ENDFOR
  179.   #IF(%SecondaryExist)                           #<!IF schema has a Secondary
  180.   DO SecondaryLookups                            !Read any lookup fields
  181.   #ENDIF
  182.   #IF(%PullDownStructure)
  183.   OPEN(%PullDown)
  184.   SAV::PullDownOpened = True
  185.   #EMBED('Setup Pulldown')                       #! Embedded Source Code
  186.   #ENDIF
  187.   OPEN(%Screen)                                  !Open the FORM screen
  188.   IF Action = DeleteRecord                       !IF request for DELETE
  189.     DISABLE(1,FIELDS())                          !Disable all screen fields
  190.     ENABLE(?OK)                                  !Enable the OK and the
  191.     ENABLE(?Cancel)                              !Cancel buttons
  192.     #FOR(%ScreenField)
  193.       #IF(UPPER(%ScreenFieldUse)='LOC:MESSAGE')
  194.     ENABLE(?LOC:Message)                         !and the message display
  195.         #BREAK
  196.       #ENDIF
  197.     #ENDFOR
  198.   END                                            !End IF request for delete
  199.   #EMBED('Setup Screen')
  200.   #SET(%ProcessingFile,%Primary)
  201.   DISPLAY                                        !Display screen fields
  202.   LOOP                                           !Begin Main process loop
  203.     #EMBED('Beginning of Accept Loop')
  204.     #IF(%SecondaryExist)                         #<!IF File schema has Secondary
  205.     #INSERT(%SecondaryChanged)
  206.     #ENDIF
  207.     #IF(%LoopFormulasExist = 'Y')             #<!Are there Formula fields?
  208.       #SET(%GenerateFormulasOn,'Y')
  209.     DO FormulaFields                             !Calculate Formula fields
  210.     #ENDIF
  211.     CASE SELECTED()                              !Process selected Field
  212.     #INSERT(%ScreenSetupRoutines)
  213.     OF NoMoreFields                              !User pressed Enter or OK
  214.       #EMBED('Before File I/O')
  215.       CASE Action                                !Process requested Action
  216.       OF AddRecord                               !Action = 1 (ADD)
  217.         ADD(%Primary)                            #<!Add Record to Primary file
  218.       OF ChangeRecord                            !Action = 2 (Change)
  219.         #IF(%AutoInc)
  220.         IF AutoIncAdd                            #<!Was this an Autonumber?
  221.           #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  222.           LastPosition = POSITION(%Primary)      #<!Save last record position
  223.           #ENDIF
  224.           PUT(%Primary)                          #<!Write the Record
  225.         ELSE                                     #<!not AutoincAdd
  226.         #ENDIF
  227.         #IF(%SharedFiles)
  228.           DO ConcurrentWrite                     !Concurrent update ROUTINE
  229.           IF AbortTransaction                    !AbortWrite is on
  230.             SELECT(?Cancel)
  231.             CYCLE                                !Let user choose response
  232.           END                                    !End AbortWrite#
  233.         #ENDIF
  234.         #IF(%UpdateChildList)
  235.           DO ConstrainedUpdate                   #<!Write the Record
  236.           IF AbortTransaction
  237.             SELECT(?Cancel)
  238.             CYCLE
  239.           END
  240.         #ELSE
  241.           PUT(%Primary)
  242.         #ENDIF
  243.         #IF(%AutoInc)
  244.         END                                      #<!IF AutoIncAdd
  245.         #ENDIF
  246.       OF DeleteRecord                            !Action = 3 (Delete)
  247.         #IF(%SharedFiles)
  248.         DO ConcurrentDelete
  249.         IF AbortTransaction
  250.           SELECT(?Cancel)
  251.           CYCLE
  252.         END
  253.         #ENDIF
  254.         #IF(%DeleteChildList)
  255.         DO ConstrainedDelete                     #<!Write the Record
  256.         IF AbortTransaction
  257.           SELECT(?Cancel)
  258.           CYCLE
  259.         END
  260.         #ELSE
  261.         DELETE(%Primary)
  262.         #ENDIF
  263.       ELSE
  264.         DO ProcedureReturn
  265.       END                                        !End CASE Action
  266.       IF ERRORCODE()                             !Error check on File I/O
  267.         #IF(%DupKeyCheck)
  268.         #INSERT(%DupKeyCode)
  269.         #ENDIF
  270.         #INSERT(%UpdateErrorMsg)
  271.         #IF(%SharedFiles)
  272.         RELEASE(%Primary)                        #<!Release the held record
  273.         FREE(RecordQueue)                        !FREE the memory Queue
  274.         #ENDIF
  275.         DISABLE(1,FIELDS())                      !Disable all the fields
  276.         ENABLE(?Cancel)                          !Enable Cancel button
  277.         SELECT(?Cancel)                          !and place cursor on Cancel
  278.         DISPLAY                                  !Re-display the screen
  279.         CYCLE                                    !Re-start main LOOP
  280.       ELSE                                       !Else no errorcode()
  281.         #IF(%SharedFiles)
  282.         FREE(RecordQueue)                        !Free memory from Queue
  283.         #ENDIF
  284.         #IF(%NextProcedure)
  285.         #EMBED('Setup Next Procedure')
  286.         %NextProcedure                           #<!Call the Next Procedure
  287.         #EMBED('Return from Next Procedure')
  288.         #ENDIF
  289.         #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  290.         IF Action = AddRecord                    #<!If Action is AddRecord
  291.           LastPosition = POSITION(%Primary)      #<!Save position of last ADD
  292.         END                                      #<!End IF Action = AddRecord
  293.         #ENDIF
  294.         #IF(UPPER(CLIP(%AddAction)) = 'CLEAR RECORD')
  295.         IF (Action = AddRecord) OR (Action = ChangeRecord AND AutoIncAdd)
  296.           #INSERT(%InsertMessage)                #<!Message for ADD RECORD
  297.           #FIX(%File,%Primary)
  298.           #INSERT(%ClearValues)
  299.           DISPLAY                                !Update screen display
  300.           #IF(%AutoInc)
  301.           DO NextAutoNumber                      !Increment autonumber key
  302.           #IF(%InitRoutine)
  303.           DO InitializeFields                    !Initial value from DataDictionary
  304.           #ENDIF
  305.           DISPLAY                                !Display screen field
  306.           #ENDIF
  307.           SELECT(1)                              !Place cursor on 1st field
  308.           #EMBED('After ADD on Retain and Clear record')
  309.           CYCLE                                  !Re-start main LOOP
  310.         END                                      !End IF (Action = ....)
  311.         #ELSIF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  312.         IF (Action = AddRecord) OR (Action = ChangeRecord AND AutoIncAdd)
  313.          #IF(%CopyKey <> %NULL)
  314.           DO SaveScrFlds                         #<!Save the Screen fields
  315.           #INSERT(%InsertMessage)                #<!Message for ADD RECORD
  316.           DISPLAY                                !Update screen display
  317.           #FIX(%File,%Primary)
  318.           CLEAR(%FilePre:Record)                 #<!Clear the record buffer
  319.          #ELSE
  320.           #IF(%AutoInc)
  321.           SAV:SaveRecord = %FilePre:Record       #<!Save the record buffer
  322.           #ENDIF
  323.          #ENDIF
  324.           DISPLAY
  325.           #IF(%AutoInc)
  326.           DO NextAutoNumber                      !Increment autonumber key
  327.           %FilePre:Record = SAV:SaveRecord       #<!Restore saved record
  328.           #INSERT(%RestoreAuto)                  #<!Restore AutoNumber(s)
  329.           DISPLAY                                !Display screen fields
  330.           #ENDIF
  331.           SELECT(1)                              !Place cursor on 1st field
  332.           #EMBED('After ADD on Retain and Clear record')
  333.           CYCLE                                  !Re-start main LOOP
  334.         END                                      !End IF (Action = ....)
  335.         #ENDIF                                   #!End %AddAction code
  336.         BREAK                                    !Break from main Loop
  337.       END                                        !End IF Errorcode()
  338.     END                                          !End CASE Selected()
  339.     ACCEPT                                       !Enable screen entry
  340.     IF NonStopSelect
  341.       IF KEYCODE()
  342.         NonStopSelect = FALSE
  343.       END
  344.     END
  345.     #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  346.      #IF(%CopyKey)
  347.     #INSERT(%DupFldCall)
  348.      #ENDIF
  349.     #ENDIF
  350.     CASE KEYCODE()
  351.       OF EscKey                                  !User pressed Escape key
  352.         IF FIELD() <> ?Cancel AND FIELD() > 0    !If user pressed Escape
  353.           SELECT(?Cancel)                        !Select Cancel button
  354.           PRESS(EnterKey)                        !Process Cancel button code
  355.           CYCLE                                  !Cycle to Accept
  356.         END                                      !Field was not Cancel button
  357.     #IF(%HotKeysExist)
  358.     #FOR(%HotKey)
  359.       OF %HotKey                                 !User defined HotKey
  360.         %HotKeyProc                              !HotKey Procedure
  361.     #ENDFOR
  362.     #ENDIF
  363.     END                                          !End CASE Keycode
  364.     CASE FIELD()                                 !Process fields
  365.    #FOR(%ScreenField)
  366.     #IF(%ScreenFieldUse = '?Ok')
  367.      OF ?Ok                                      !On the OK button
  368.           #IF(%ScreenFieldEdit <> %NULL)
  369.         %ScreenFieldEdit                         #<!Field Edit procedure
  370.           #ENDIF
  371.         SELECT(1)                                !Start with the first field
  372.         SELECT                                   !and cycle non-stop
  373.         NonStopSelect = TRUE                     !Set Up for Non-Stop Select
  374.         SETKEYCODE(0)                            !Clear the KeyCode
  375.         CYCLE                                    !restart main process loop
  376.     #ELSIF(%ScreenFieldUse = '?Cancel')
  377.      OF ?Cancel                                  !On Cancel button
  378.       #IF(%AutoInc = 'Y')
  379.         IF AutoIncAdd                            !ADDed autoincrement record?
  380.           RESET(%Primary,AutoAddPtr)             #<!Re-position record pointer
  381.           NEXT(%Primary)                         #<!Re-read the record we added
  382.           IF DiskError('Could not READ Record')  !Check for file I/O error
  383.             DO ProcedureReturn
  384.           END                                    !End IF Diskerror
  385.           DELETE(%Primary)                       #<!DELETE the record
  386.           IF DiskError('Record could not be Deleted')
  387.             DO ProcedureReturn
  388.           END                                    !End IF Diskerror
  389.         END                                      !End IF AutoIncAdd
  390.       #ENDIF
  391.           #IF(%ScreenFieldEdit <> %NULL)
  392.         %ScreenFieldEdit                         #<!Field edit procedure
  393.           #ENDIF
  394.         #IF(UPPER(CLIP(%AddAction)) <> 'RETURN TO CALLER')
  395.         IF LastPosition                          #<!IF a record was added
  396.           RESET(%Primary,LastPosition)           #<!Position to the record
  397.           NEXT(%Primary)                         #<!and read it
  398.         ELSE                                     #<!Else no LastPosition
  399.           GET(%Primary,0)                        #<!signal Browse to re-read
  400.         END                                      #<!END If LastPosition
  401.         #ELSE
  402.         IF Action <> DeleteRecord                #<! IF not called to delete
  403.           GET(%Primary,0)                        #<! signal Browse to re-read
  404.         END                                      #<! END (IF not called...)
  405.         #ENDIF
  406.         DO ProcedureReturn
  407.     #ELSE
  408.     #INSERT(%ScreenEditRoutines)
  409.     #ENDIF
  410.    #ENDFOR
  411.    #FOR(%PulldownField)                         #! add all procedure or
  412.     #IF(%PulldownFieldType = 'PROCEDURE')       #! source code calls
  413.      OF %PulldownField                         #<!For a Pulldown field
  414.        %PulldownFieldProc                      #<!  execute its procedure
  415.     #ENDIF
  416.    #ENDFOR
  417.     END                                          !End CASE FIELD
  418.   END                                            !END MAIN PROCESS LOOP
  419.   #FOR(%Formula)
  420.     #IF(UPPER(%FormulaClass) = 'RETURN')
  421.   #INSERT(%GenerateFormula)                      #<!Return Class formula
  422.     #ENDIF
  423.   #ENDFOR
  424.   DO ProcedureReturn
  425. !─────────────────────────────────────────────────────────────────────────────
  426. ProcedureReturn ROUTINE
  427.   #IF(%SharedFiles)
  428.      #IF(%AutoInc)
  429.   IF Action = ChangeRecord AND AutoIncAdd
  430.     RELEASE(%Primary)
  431.   END
  432.     #ENDIF
  433.   #ENDIF
  434.   #IF(%PullDownStructure)
  435.   IF SAV::PullDownOpened
  436.     CLOSE(%PullDown)
  437.   END
  438.   #ENDIF
  439.   #IF(%SharedFiles)
  440.   FREE(RecordQueue)
  441.   #ENDIF
  442.   #EMBED('Before Closing Screen')
  443.   #EMBED('Before Closing Files')
  444.   #INSERT(%FileControl)                          #!Open files
  445.   DO EndOfProcedureEmbed
  446.   RETURN
  447. !─────────────────────────────────────────────────────────────────────────────
  448. EndOfProcedureEmbed ROUTINE
  449. #EMBED('End of Procedure')
  450. #EMBED('Custom Routines')
  451. #INSERT(%AutoIncCode)
  452. #INSERT(%ConcurrentWrite)
  453. #INSERT(%ConcurrentDelete)
  454. #INSERT(%RIUpdates)
  455. #INSERT(%RIDeletes)
  456. #INSERT(%InitQue)
  457. #INSERT(%InitFields)
  458. #INSERT(%GenFormulas)
  459. #IF(%SecondaryExist)
  460. #INSERT(%SecondaryLookups)
  461. #ENDIF
  462. #IF(UPPER(CLIP(%AddAction)) = 'RETAIN RECORD')
  463.  #IF(%CopyKey)
  464. #INSERT(%SaveScrFlds)
  465. #INSERT(%DupField)
  466.  #ENDIF
  467. #ENDIF
  468. #CHAIN('MultiPg.tpx')
  469.